package com.rjet.access_control.socket;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @Author:ethan
 * @Date: 2023/10/12  16:56
 * @Version 1.0.1
 */
public class TcpServer  {

    private ServerSocket serverSocket;
    private Socket socket;
    private OutputStream os;
    private InputStream is;

    public void tcp()
    {
        try {
            serverSocket = new ServerSocket(8081);
            socket = serverSocket.accept();

            while (true){

                is = socket.getInputStream();
                os = socket.getOutputStream();

                //IO读取
                byte[] buf = new byte[1024];
                int readlen = 0;
                while((readlen = is.read(buf))!= -1){
                    System.out.println(new String(buf,0,readlen));
                }

            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
